package com.gzqylc.docker.extend.gateway.controller;

import com.gzqylc.docker.extend.gateway.bo.HttpRequestBO;
import com.gzqylc.docker.extend.gateway.domain.GateWayConfig;
import com.gzqylc.docker.extend.gateway.service.GateWayConfigService;
import com.gzqylc.framework.AjaxResult;
import com.gzqylc.framework.Route;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Desc：TODO
 * @ClassName GateWayConfigController
 * @Author 孔晓文
 * @Date 2022/2/16 下午3:36
 */
@RestController
@Slf4j
@Route(value = "api/extend/gateWay/")
public class GateWayConfigController {

    @Autowired
    GateWayConfigService gWayConfigService;

    @Route("page")
    public Page<GateWayConfig> page(GateWayConfig gatewayConfig, Pageable pageable){
        return gWayConfigService.page(gatewayConfig,pageable);
    }

    @Route("saveOrUpdate")
    public AjaxResult saveOrUpdate(@RequestBody GateWayConfig gatewayConfig){
        gWayConfigService.saveOrUpdate(gatewayConfig);
        return AjaxResult.success();
    }
    @Route("delete")
    public AjaxResult delete(@RequestParam String id){
        gWayConfigService.delete(id);
        return AjaxResult.success();
    }

    @Route("getConfig")
    public String getConfig(@RequestBody HttpRequestBO bo){
        return gWayConfigService.getConfig(bo.getUrl(),bo.getCode());
    }

    @Route("updateConfig")
    public AjaxResult updateConfig(@RequestBody HttpRequestBO bo){
        gWayConfigService.updateConfig(bo.getUrl(),bo.getCode(),bo.getData());
        return AjaxResult.success();
    }

}
